package com.qk.server.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.entity.Activity;
import com.qk.mapper.ActivityMapper;
import com.qk.server.ActivityServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
@Slf4j
@Service
public class ActivityServerImpl implements ActivityServer {
    @Autowired
    ActivityMapper activityMapper;
    @Override
    public PageResult<Activity> findActivityByList(Integer channel, Integer type, Integer status, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<Activity> list =  activityMapper.selectActivityByList(channel,type,status);
        Page<Activity> activityPage = (Page<Activity>) list;
        return new PageResult<>(activityPage.getTotal(),activityPage.getResult());
    }

    @Override
    public void delActivityById(Integer id) {
        activityMapper.delActivityById(id);
    }

    @Override
    public void addActivity(Activity activity) {
        activity.setCreateTime(LocalDateTime.now());
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.instalActivity(activity);
    }

    @Override
    public Activity findActivityById(Integer id) {
        return activityMapper.selectActivityById(id);
    }

    @Override
    public void updateActivity(Activity activity) {
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.updateActivity(activity);
    }

    @Override
    public List<Activity> findActivityByType(Integer type) {
        log.info("查询活动类型为{}的活动",type);
        return activityMapper.selectActivityByType(type);
    }
}
